package com.ruoyi.examination.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.examination.domain.AnswerRecord;
import com.ruoyi.examination.service.IAnswerRecordService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 答题记录Controller
 * 
 * @author hcc
 * @date 2025-10-21
 */
@RestController
@RequestMapping("/answerRecord")
public class AnswerRecordController extends BaseController
{
    @Autowired
    private IAnswerRecordService answerRecordService;

    /**
     * 查询答题记录列表
     */
    @RequiresPermissions("examination:answerRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(AnswerRecord answerRecord)
    {
        startPage();
        List<AnswerRecord> list = answerRecordService.selectAnswerRecordList(answerRecord);
        return getDataTable(list);
    }

    /**
     * 导出答题记录列表
     */
    @RequiresPermissions("examination:answerRecord:export")
    @Log(title = "答题记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AnswerRecord answerRecord)
    {
        List<AnswerRecord> list = answerRecordService.selectAnswerRecordList(answerRecord);
        ExcelUtil<AnswerRecord> util = new ExcelUtil<AnswerRecord>(AnswerRecord.class);
        util.exportExcel(response, list, "答题记录数据");
    }

    /**
     * 获取答题记录详细信息
     */
    @RequiresPermissions("examination:answerRecord:query")
    @GetMapping(value = "/{answerRecordId}")
    public AjaxResult getInfo(@PathVariable("answerRecordId") String answerRecordId)
    {
        return success(answerRecordService.selectAnswerRecordByAnswerRecordId(answerRecordId));
    }

    /**
     * 新增答题记录
     */
    @RequiresPermissions("examination:answerRecord:add")
    @Log(title = "答题记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AnswerRecord answerRecord)
    {
        return toAjax(answerRecordService.insertAnswerRecord(answerRecord));
    }

    /**
     * 修改答题记录
     */
    @RequiresPermissions("examination:answerRecord:edit")
    @Log(title = "答题记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AnswerRecord answerRecord)
    {
        return toAjax(answerRecordService.updateAnswerRecord(answerRecord));
    }

    /**
     * 删除答题记录
     */
    @RequiresPermissions("examination:answerRecord:remove")
    @Log(title = "答题记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{answerRecordIds}")
    public AjaxResult remove(@PathVariable String[] answerRecordIds)
    {
        return toAjax(answerRecordService.deleteAnswerRecordByAnswerRecordIds(answerRecordIds));
    }
}
